﻿using Yitter.IdGenerator;

namespace RpcHelper.IdGenerator
{
    public class IdentityHelper
    {
        public static void Init(IdentityConfig config)
        {
            IdGeneratorOptions options = new(config.WorkId)
            {
                WorkerIdBitLength=config.WorkerIdBitLength,
                SeqBitLength = config.SeqBitLength,
                BaseTime=config.BaseTime,
                Method=config.Method,
                MaxSeqNumber = config.MaxSeqNumber,
                MinSeqNumber = config.MinSeqNumber,
                DataCenterId = config.DataCenterId,
                TimestampType = config.TimestampType,
                DataCenterIdBitLength = config.DataCenterIdBitLength
            };
            YitIdHelper.SetIdGenerator(options);
        }

        public static long CreateId()
        {
            return YitIdHelper.NextId();
        }
    }
}
